package com.kt.uokos.yimo.controller;

import com.kt.uokos.yimo.anno.validator.Order;
import com.kt.uokos.yimo.anno.validator.Sort;
import com.kt.uokos.yimo.dao.Comment;
import com.kt.uokos.yimo.service.CommentService;
import com.kt.uokos.yimo.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: TODO
 * @className: Comment.java
 * @author: Kang Hao
 * @date: 2022/4/28 16:53
 **/

@RestController
@RequestMapping("/admin/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/list")
    public Object list(Integer userId, Integer valueId,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order){
        List<Comment> commentList = commentService.queryList(userId, valueId, page, limit, sort, order);

        return ResponseUtil.okList(commentList);
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody Comment comment){
        if (comment == null){
            return ResponseUtil.errs();
        }
        commentService.delete(comment);
        return ResponseUtil.ok();
    }
}
